package com.controller;

import com.pojo.ShopCommentCommentary;
import com.service.ShopCommentCommentaryService;
import com.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2020/3/20.
 */
@Api(tags = "商品评论点赞API")
@Controller
public class ShopCommentCommentaryController {
    @Autowired
    private ShopCommentCommentaryService shopCommentCommentaryService;
    @ApiOperation(value ="添加点赞",notes ="" )
    @PostMapping("/shopCommentCommentary")
    @ResponseBody
    public ServerResponse add(ShopCommentCommentary shopCommentCommentary){
        // ServerResponse serverResponse =
        //System.out.println("serverResponse:"+serverResponse);
        return shopCommentCommentaryService.save(shopCommentCommentary);
    }
    @ApiOperation(value = "删除评论的点赞",notes ="修改状态")
    @DeleteMapping("/shopCommentCommentary/{id}")
    @ResponseBody
    public ServerResponse del(@PathVariable("id")String id){
        ServerResponse serverResponse = shopCommentCommentaryService.modifyStatus(Integer.valueOf(id));
        System.out.println("serverResponse:"+serverResponse);
        return serverResponse;
    }

    @ApiOperation(value ="修改点赞",notes ="应该用不到" )
    @PutMapping("/shopCommentCommentary")
    @ResponseBody
    public ServerResponse upd(ShopCommentCommentary shopCommentCommentary){
        System.out.println(shopCommentCommentary);
        ServerResponse serverResponse = shopCommentCommentaryService.modify(shopCommentCommentary);
        return serverResponse;
    }
    @ApiOperation(value ="根据点赞id查询")
    @GetMapping("/shopCommentCommentary/{id}")
    @ResponseBody
    public ServerResponse findById(@PathVariable("id") String id){
        System.out.println(id);
        ServerResponse serverResponse = shopCommentCommentaryService.getById(Integer.valueOf(id));
        return serverResponse;
    }

    @ApiOperation(value ="查询点赞信息")
    @GetMapping("/shopCommentCommentary")
    public String  findAll(Model model){
        ServerResponse serverResponse = shopCommentCommentaryService.getAll();
        model.addAttribute("info",serverResponse.getData());
        return "back/shop/shopCommentCommentary";
    }
}
